<?php
namespace Admin\Controller;
class LinkCateController extends CommonController{
    public function _initialize(){
        parent::_initialize();
        $this->_mod = D('LinkCate');
    }

    public function _before_index() {
        $big_menu = array(
            'title' => '增加分类',
            'iframe' => U('LinkCate/add'),
            'id' => 'add',
            'width' => '400',
            'height' => '90'
        );
        $this->assign('big_menu', $big_menu);
        $this->sort = 'ordid';
        $this->order = 'ASC';
    }

    public function ajax_check_name() {
        $name = I('name');
        $id = I('id', 0,'intval');
        if ($this->name_exists($name,$id)) {
            $this->ajaxReturn(0, L('flink_cate_already_exists'));
        } else {
            $this->ajaxReturn(1);
        }
    }

	public function name_exists($name,$id=0){
		$pk = $this->_mod->getPk();
        $where = "name='" . $name . "'  AND ". $pk ."<>'" . $id . "' AND site_id=".$this->siteId;
		$result=$this->_mod->where($where)->count($pk);
		if($result){
			return 1;
		}else{
			return 0;
		}
	}
}